package com.anyisn.flickr.as3.patterns.proxy
{
	import com.adobe.webapis.flickr.events.FlickrResultEvent;
	
	import com.anyisn.anyflickr.shell.model.vo.PhotoListVO;
	import com.anyisn.anyflickr.shell.model.vo.SearchVO;

	public class FlickrPhotosProxy extends FlickrServiceProxy
	{
		public var searchVO:SearchVO;
		protected var lastList:PhotoListVO;
		protected var nsid:String;
		public var currentList:PhotoListVO;
		
		public function FlickrPhotosProxy(proxyName:String=null, data:Object=null)
		{
			super(proxyName, data);
		}
		
		// PHOTOS_SEARCH
		public function search(vo:SearchVO, page:uint = 1):void {
			searchVO = vo;
			service.addEventListener(FlickrResultEvent.PHOTOS_SEARCH, onPhotosSearch);
			service.photos.search(	"", 
									vo.tags, 
									vo.tag_mode, 
									vo.text, 
									vo.min_upload_date, 
									vo.max_upload_date, 
									vo.min_taken_date, 
									vo.max_taken_date, 
									-1, 
									vo.sort, 
									-1,
									"",
									-1,
									-1,
									-1,
									"",
									"",
									"",
									"",
									"",
									"",
									"",
									false,
									"",
									"",
									-1,
									-1,
									"",
									perpage,
									page);
		}
		
		protected function onPhotosSearch(event:FlickrResultEvent):void {
			service.removeEventListener(FlickrResultEvent.PHOTOS_SEARCH, onPhotosSearch);
		}
		
		// INTERESTINGNESS_GET_LIST
		public function getInterestingnessList(page:uint = 1):void {
			service.addEventListener(FlickrResultEvent.INTERESTINGNESS_GET_LIST, onInterestingnessGetList);
			service.interestingness.getList(null, "", perpage, page);
		}

		protected function onInterestingnessGetList(event:FlickrResultEvent):void {
			service.removeEventListener(FlickrResultEvent.INTERESTINGNESS_GET_LIST, onInterestingnessGetList);
		}
		
		// PEOPLE_GET_PUBLIC_PHOTOS
		public function getPeoplePublicPhotos(id:String, page:uint = 1):void {
			nsid = id;
			service.addEventListener(FlickrResultEvent.PEOPLE_GET_PUBLIC_PHOTOS, onPeopleGetPublicPhotos);
			service.people.getPublicPhotos(id, "", perpage, page);
		}
		
		protected function onPeopleGetPublicPhotos(event:FlickrResultEvent):void {
			service.removeEventListener(FlickrResultEvent.PEOPLE_GET_PUBLIC_PHOTOS, onPeopleGetPublicPhotos);
		}
		
		// FAVORITES_GET_LIST
		public function getFavoritesList(page:uint = 1):void {
			service.addEventListener(FlickrResultEvent.FAVORITES_GET_LIST, onGetFavoritesList);
			service.favorites.getList("", "", perpage, page);
		}
		
		protected function onGetFavoritesList(event:FlickrResultEvent):void {
			service.removeEventListener(FlickrResultEvent.FAVORITES_GET_LIST, onGetFavoritesList);
		}
		
		// gettor
		protected function get perpage():uint {
			return 100;
		}
	}
}